package com.ruoyi.ylyx.controller;

import java.util.List;

import com.ruoyi.ylyx.domain.YlyxGametype;
import com.ruoyi.ylyx.service.IYlyxGametypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ylyx.domain.YlyxGame;
import com.ruoyi.ylyx.service.IYlyxGameService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 游戏档案Controller
 * 
 * @author yuexl
 * @date 2021-02-05
 */
@Controller
@RequestMapping("/ylyx/game")
public class YlyxGameController extends BaseController
{
    private String prefix = "ylyx/game";

    @Autowired
    private IYlyxGameService ylyxGameService;
    @Autowired
    private IYlyxGametypeService ylyxGametypeService;

    @RequiresPermissions("ylyx:game:view")
    @GetMapping()
    public String game(ModelMap mmap)
    {
        mmap.put("posts", ylyxGametypeService.selectYlyxGametypeList(new YlyxGametype()));
        return prefix + "/game";
    }

    /**
     * 查询游戏档案列表
     */
    @RequiresPermissions("ylyx:game:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YlyxGame ylyxGame)
    {
        startPage();
        List<YlyxGame> list = ylyxGameService.selectYlyxGameList(ylyxGame);
        return getDataTable(list);
    }

    /**
     * 导出游戏档案列表
     */
    @RequiresPermissions("ylyx:game:export")
    @Log(title = "游戏档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YlyxGame ylyxGame)
    {
        List<YlyxGame> list = ylyxGameService.selectYlyxGameList(ylyxGame);
        ExcelUtil<YlyxGame> util = new ExcelUtil<YlyxGame>(YlyxGame.class);
        return util.exportExcel(list, "game");
    }

    /**
     * 新增游戏档案
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("posts", ylyxGametypeService.selectYlyxGametypeList(new YlyxGametype()));
        return prefix + "/add";
    }

    /**
     * 新增保存游戏档案
     */
    @RequiresPermissions("ylyx:game:add")
    @Log(title = "游戏档案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YlyxGame ylyxGame)
    {
        return toAjax(ylyxGameService.insertYlyxGame(ylyxGame));
    }

    /**
     * 修改游戏档案
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        YlyxGame ylyxGame = ylyxGameService.selectYlyxGameById(id);
        mmap.put("ylyxGame", ylyxGame);
        mmap.put("types", ylyxGametypeService.selectTypeByGameId(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存游戏档案
     */
    @RequiresPermissions("ylyx:game:edit")
    @Log(title = "游戏档案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YlyxGame ylyxGame)
    {
        return toAjax(ylyxGameService.updateYlyxGame(ylyxGame));
    }

    /**
     * 删除游戏档案
     */
    @RequiresPermissions("ylyx:game:remove")
    @Log(title = "游戏档案", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ylyxGameService.deleteYlyxGameByIds(ids));
    }
}
